
package com.hnrd.crud.exceptionHandler;

import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.LoginException;

import org.apache.shiro.authc.AuthenticationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.auth0.jwt.exceptions.JWTDecodeException;

@ControllerAdvice
public class UnifiedExceptionHandler {
	private Map<String, String> map=new HashMap<>();
	@ExceptionHandler(value=JWTDecodeException.class)
	public ResponseEntity<Map<String,String>> GetExcepiton(){
		map.put("msg","当前token已失效，请重新登录！");
		return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);	
	}
	
	@ExceptionHandler(value=AuthenticationException.class)
	public ResponseEntity<Map<String,String>> noPermissionExcepiton(){
		map.put("msg","当前用户没有该权限");
		return new ResponseEntity<>(map,HttpStatus.UNAUTHORIZED);	
	}
	
	@ExceptionHandler(value=LoginException.class)
	public ResponseEntity<Map<String,String>> unLoginException(){
		map.put("msg", "用户未登陆或session过期，请重新登陆！");
		return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);		
	}
}
